<?php 

$DEMO_PLAYLISTS = Array();

header('Content-type: application/x-javascript');
require('auth.php');

function base64url_decode($base64url) {
	$base64 = strtr($base64url, '-_', '+/');
	$plainText = base64_decode($base64);
	return ($plainText);
}
function base64url_encode($plainText) {
	$base64 = base64_encode($plainText);
	$base64url = strtr($base64, '+/', '-_');
	return ($base64url);   
}

if (!file_exists($ITUNES_PLAYLIST_FOLDER)) {
	echo "//iTunes Playlists folder does not exist at path $ITUNES_PLAYLIST_FOLDER";
	exit;
}

$FOLDER_IGNORES = array("Icon","Icon\x0D" ,"index.php", "TheVolumeSettingsFolder");

$files = array();
$dir_handle = @opendir($ITUNES_PLAYLIST_FOLDER) or die("//Unable to open $playlistsDir");
while ($file = readdir($dir_handle)) if ($file{0} != '.' && in_array("$file",$FOLDER_IGNORES)==false && strpos($file,'.xml')!== false) 
	$files[] = $file;
natcasesort($files);
closedir($dir_handle);


foreach ($files as $stritem) {
	$outdir = "$ITUNES_PLAYLIST_FOLDER/$stritem";	
	$getdir = base64url_encode($outdir);
	$filetitle = basename($stritem,'.xml');

	echo 'Musiker.modHardPlaylists.playlistsByName["'.$filetitle.'"] = "'.$getdir.'";'."\n";
}	

if ($MUSIKER_DEMOMODE) { ?>
Musiker.demoMode = {
	AllowedPlaylists : Array(
<?php foreach($DEMO_PLAYLISTS as $pl) echo "\t\t'$pl',\n"?>
		null
	)
}
<?php } ?>

LoadProgress.completeModule('Playlists');